/**
 * Created by Administrator on 2017/9/7.
 */
let qrImage = require('qr-image');
let variable = require('../data/variable.js');
let util = require('../util/util.js');
let rpc = require('../util/rpc.js');

let method = module.exports;

method.qrCode = function (req, res) {
    let data = util.getRequestParam(req);
    let url = variable.weixin.jion_url + '&fromUid=' + data.fromUid + '&roomId=' + data.roomId;
    let tempQrCode = qrImage.image(url);
    res.type('png');
    res.header('Content-Type', 'image/png');
    res.header('Access-Control-Allow-Origin', '*');
    tempQrCode.pipe(res);
};  

method.wxShare = function (req, res) {
    let data = util.getRequestParam(req);
    let url = variable.weixin.jion_url + '&fromUid=' + data.userId + '&roomId=' + data.roomId;
    let tempQrCode = qrImage.image(url);
    res.type('png');
    res.header('Content-Type', 'image/png');
    res.header('Access-Control-Allow-Origin', '*');
    tempQrCode.pipe(res);
};  

method.getGames = function (req, res) {
    res.header('Access-Control-Allow-Origin', '*');
    rpc.dc.send('getGames', null, function (result) {
        res.send(result).end();
    });
};
method.killGame = function (req, res) {
    let data = util.getRequestParam(req);
    res.header('Access-Control-Allow-Origin', '*');
    rpc.dc.send('killGame', data, function (result) {
        res.send(result).end();
    });
};
method.alertMsg = function(req, res) {
    let data = util.getRequestParam(req);
    res.header('Access-Control-Allow-Origin', '*');
    rpc.dc.send('alertMsg', data, function (result) {
        res.send(result).end();
    });
};